#!/bin/bash 
# chkconfig: - 60 50
# description: rsync server
# processname: rsyncd
 
status1=$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v 'grep') 
pidfile="/usr/local/server/rsync/run/rsyncd.pid" 
start_rsync="rsync --daemon --config=/usr/local/rsync/etc/rsyncd.conf" 
 
function rsyncstart() { 
 
    if [ "${status1}X" == "X" ];then
        ${start_rsync}    
        status2=$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v 'grep') 
         
        if [  "${status2}X" != "X"  ];then 
             
            echo "rsync service start.......OK" 
             
        fi 
 
    else 
 
        echo "rsync service is running !"    
 
    fi 
} 
 
function rsyncstop() { 
 
    if [ "${status1}X" != "X" ];then 
     
        kill -9 $(cat $pidfile)
        rm -f $pidfile
 
        status2=$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v 'grep') 
 
        if [ "${statusw2}X" == "X" ];then 
             
            echo "rsync service stop.......OK" 
        fi 
    else 
 
        echo "rsync service is not running !"    
 
    fi 
} 
 
 
function rsyncstatus() { 
 
 
    if [ "${status1}X" != "X" ];then 
 
        echo "rsync service is running !"   
     
    else 
 
         echo "rsync service is not running !"  
 
    fi 
 
} 
 
function rsyncrestart() { 
 
    if [ "${status1}X" == "X" ];then
 
          echo "rsync service is not running..." 
 
          rsyncstart 
 
      else
 
          rsyncstop
          rsync --daemon --config=/usr/local/server/rsync/etc/rsyncd.conf
          status2=$(ps -ef | egrep "rsync --daemon.*rsyncd.conf" | grep -v 'grep')          
 
        if [  "${status2}X" != "X"  ];then              
    
            echo "rsync service start.......OK"       
 
        else 
 
            echo "rsync service is not running !" 
 
        fi
 
    fi  
}  
 
case "$1" in 
 
        "start") 
               rsyncstart 
                ;; 
 
        "stop") 
               rsyncstop 
                ;; 
 
        "status") 
               rsyncstatus 
               ;; 
 
        "restart") 
               rsyncrestart
               ;; 
 
        *) 
          echo 
                echo  "Usage: $0 start|stop|restart|status" 
          echo 
esac
